package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing")
@Slf4j
@Api(tags = "护理计划")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;

    @ApiOperation("查询所有护理计划")
    @GetMapping("/plan")
    public ResponseResult getAll() {
        log.info("查询所有护理计划");
        List<NursingPlanVo> list = nursingPlanService.getAll();
        return ResponseResult.success(list);
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/plan/search")
    public ResponseResult<PageResponse<NursingPlanVo>> search(
            @ApiParam(value = "护理计划名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "护理计划状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingPlanVo> nursingPlanVoPageInfo = nursingPlanService.search(name, status, pageNum, pageSize);

        //开发阶段将count设置为零
//        nursingPlanVoPageInfo.getRecords().forEach(nursingPlanVo -> nursingPlanVo.setCount(0));
        return ResponseResult.success(nursingPlanVoPageInfo);
    }

    @ApiOperation("新增护理计划")
    @PostMapping("/plan")
    public ResponseResult add(@RequestBody NursingPlanVo nursingPlanVo) {
        log.info("新增护理计划");
        nursingPlanService.add(nursingPlanVo);
        return ResponseResult.success();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/plan/{id}")
    public ResponseResult getNursingPlanById(@PathVariable Long id) {
        log.info("根据id查询护理计划");
        NursingPlanVo nursingPlanVo = nursingPlanService.getNursingPlanById(id);
        return ResponseResult.success(nursingPlanVo);
    }

    @ApiOperation("修改")
    @PutMapping("/plan/{id}")
    public ResponseResult update(@RequestBody NursingPlanVo nursingPlanVo) {
        log.info("修改护理计划");
        nursingPlanService.update(nursingPlanVo);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult status(@PathVariable Long id, @PathVariable Integer status) {
        log.info("启用禁用");
        nursingPlanService.status(id, status);
        return ResponseResult.success();
    }

    @ApiOperation("删除")
    @DeleteMapping("/plan/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        log.info("删除护理计划");
        nursingPlanService.deleteNursingProjectPlanById(id);
        return ResponseResult.success();
    }
}
